#ifndef _VM_VM_H

#define _VM_VM_H

#include "common.h"
#include "header_obj.h"
#include "parser.h"
#include "obj_fn.h"
#include "obj_list.h"
#include "obj_string.h"
#include "obj_map.h"
#include "class.h"
#include "utils.h"

#define OPCODE_SLOTS(opcode, effect) OPCODE_##opcode,
typedef enum {
    #include "opcode.inc"
} OpCode;
#undef OPCODE_SLOTS

typedef enum vmResult
{
    VM_RESULT_SUCCESS, VM_RESULT_ERROR
} VMResult; // 虚拟机执行结果

struct vm {
    Class *class_of_class;
    Class *object_class;
    Class *map_class;
    Class *range_class;
    Class *list_class;
    Class *fn_class;
    Class *string_class;
    Class *null_class;
    Class *bool_class;
    Class *num_class;
    Class *thread_class;
    uint32_t allocated_bytes; // 累计已分配的内存
    ObjHeader *allo_objects; // 所有已分配对象链表
    Parser *cur_parser; // 当前词法分析器
    SymbolTable all_method_names; // 所有类的方法名
    ObjMap *all_modules;
    ObjThread *cur_thread; // 当前正在执行的线程
};

void init_vm(VM *vm);
VM* new_vm(void );

#endif